diff options
Diffstat (limited to 'src/routes/(app)/invoice/[id]/+layout.server.ts')
| -rw-r--r-- | src/routes/(app)/invoice/[id]/+layout.server.ts | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/routes/(app)/invoice/[id]/+layout.server.ts b/src/routes/(app)/invoice/[id]/+layout.server.ts index 590e5d4d..d6ab979e 100644 --- a/src/routes/(app)/invoice/[id]/+layout.server.ts +++ b/src/routes/(app)/invoice/[id]/+layout.server.ts @@ -12,25 +12,29 @@ export async function load({ cookies, depends, params, url, parent }) { if (id) { invoice = await get(`/invoice/${id}`); const options = !!url.searchParams.get("options"); - - if ( - user && - invoice.uid !== user.id && - !(url.pathname.includes("tip") || url.pathname.includes("memo")) && - !options - ) { - redirect(307, `/send/invoice/${id}`); - } - let { amount, pending, received } = invoice; amount = parseInt(amount); - subject = invoice.user; const paid = (!amount && (pending || received)) || (amount > 0 && (pending >= amount || received >= amount)); if (paid && !url.pathname.endsWith("paid")) { - redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : "")); + if (invoice.uid === user.id) + redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : "")); + else redirect(307, `/pay/${subject.username}/${invoice.amount}`); + } + + subject = invoice.user; + + if ( + user && + invoice.uid !== user.id && + !(url.pathname.includes("tip") || url.pathname.includes("memo")) && + !options + ) { + if (invoice.prompt && invoice.tip === null) + redirect(307, `/invoice/${id}/tip`); + else redirect(307, `/send/invoice/${id}`); } } |
